package com.mall.api.controller;

import com.mall.api.common.returnData.R;
import com.mall.api.entity.BannerEntity;
import com.mall.api.service.BannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * banner
 * @author venus
 * @date 2020/04/28
 */
@Api(tags = "测试接口")
@RestController
@RequestMapping(value = "/Banner")
public class BannerController {

    @Autowired
    private BannerService bannerService;

    /**
     * [新增]
     * @author venus
     * @date 2020/04/28@Api(value = "用户接口", description = "用户接口", tags = {"1.1.0"}
     **/
    @ApiOperation("新增banner")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public int insert(BannerEntity banner){
        return bannerService.insert(banner);
    }

    /**
     * [刪除]
     * @author venus
     * @date 2020/04/28
     **/
    @ApiOperation("物理刪除banner")
    @PostMapping("/delete")
    public int delete(int id){
        return bannerService.delete(id);
    }

    /**
     * [更新]
     * @author venus
     * @date 2020/04/28
     **/
    @PostMapping("/update")
    @ApiOperation("更新banner")
    public int update(BannerEntity bannerEntity){
        return bannerService.update(bannerEntity);
    }

    /**
     * [查询] 根据主键 id 查询
     * @author venus
     * @date 2020/04/28
     **/
    @ApiOperation("[查询] 根据主键 id 查询banner")
    @GetMapping("/load")
    public R load(int id){
        BannerEntity load = bannerService.load(id);
        return R.ok().put("load",load);
    }

    /**
     * [查询] 分页查询
     * @author venus
     * @date 2020/04/28
     **/
    @ApiOperation(value = "[查询] 分页查询banner")
    @GetMapping("/pageList")
    public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int offset,
                                        @RequestParam(required = false, defaultValue = "10") int pagesize) {
        return bannerService.pageList(offset, pagesize);
    }

}
